package com.yenroc.ho.interceptor;

import com.yenroc.ho.consts.CommonConsts;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignConfiguration implements RequestInterceptor {

    private final Logger log = LoggerFactory.getLogger(FeignConfiguration.class);

    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 将当前线程名放到请求头中,被调用方会拦截到请求头的信息,重写线程名,达到完整的调用链路径
        requestTemplate.header(CommonConsts.THREAD_ID, Thread.currentThread().getName());
        log.debug("feign interceptor header:{}", requestTemplate);
    }
}
